'''
Created on Nov 10, 2010

@author: dexen
'''


"""
import tempfile

print tempfile.gettempdir()

print tempfile.mkdtemp(prefix="HAHA")
"""

import sys
import multiprocessing as mp
import time

class SubTest(mp.Process):
    def __init__(self):
        mp.Process.__init__(self)
        
    def run(self):
        while True:
            time.sleep(1)
            print "I am subtest"

class Test(mp.Process):
    def __init__(self):
        mp.Process.__init__(self)
    
    def run(self):
        try:
            print "I am in test"
            print "Myid:", self.pid
            print "My deamonic is", self.daemon
            p = SubTest()
            p.daemon = False
            #p.start()
            while True:
                print "I am test"
                break
        except:
            print "I am terminated"
    
p = Test()
p.daemon = False
p.start()
time.sleep(4)
p.terminate()
sys.exit()

import time

class A(object):
    def __init__(self):
        self.x = 4

st = time.time()
ll = []
for _ in range(1000000):
    ll.append(A())
print "1st loop takes", time.time() - st, "seconds"

t = 0
st = time.time()
for a in ll:
    assert isinstance(a, A)
    t += a.x
print "2nd loop takes", time.time() - st, "seconds"